package com.shd.edanpei.util;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.support.annotation.Nullable;

public class KillSelfServer extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    private static long stopDelayed =1000;
    private Handler handler;
    private String PackageName;
    public KillSelfServer() {
        handler =new Handler();
    }
        @Override
    public int onStartCommand(final Intent intent, int flags, int startId)
    {
        stopDelayed = intent.getLongExtra("Delayed", 1000);
    PackageName = intent.getStringExtra("PackageName");
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(PackageName);
                startActivity(LaunchIntent);
                KillSelfServer.this.stopSelf();
            }}, stopDelayed);
        return super.onStartCommand(intent, flags, startId);
    }


}
